import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class LeetCode {
    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for (int i=0;i<s.length();i++){
            char ch=s.charAt(i);
            if (ch =='{'||ch=='['||ch=='(') {
                stack.push(ch);
            }
            //遇到右括号了
            if(stack.isEmpty()){
                return false;
            }
            if(ch=='}'&&stack.peek()=='{'||ch==')'&&stack.peek()=='('||ch==']'&&stack.peek()=='['){
                stack.pop();
            }
        }
        return true;

    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (String X:tokens){
            if(!isOperation(X)){
                stack.push(Integer.parseInt(X));
            }
            else {
                int num2=stack.pop();
                int num1=stack.pop();
                switch (X){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.peek();
    }

    private boolean isOperation(String x) {
        if(x.equals("+")||x.equals("-")||x.equals("*")||x.equals("/")){
            return true;
        }
        return false;
    }
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer>stack=new Stack<>();
        int j=0;
        for (int i=0;i<pushV.length;i++){
            stack.push(pushV[i]);

            while (!stack.isEmpty()&&j<popV.length&&popV[j]==stack.peek()){
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }





}
